-- User: chenyiqun redis connection pool
local redis = require "resty.redis"
local function close_redis(red)
    if not red then
        return
    end
    -- release conn
    local pool_max_idle_time =  10000 -- 毫秒
    local pool_size = 100 -- 连接池大小
    local ok,err = red:set_keepalive(pool_max_idle_time,pool_size)
    if not ok then
        print("set keepalive error:",err)
    end
end

local red = redis:new()
red:set_timeout(1000) -- 1 sec

local ok,err = red:connect("10.206.2.36",6379)
if not ok then
    print("failed to connection:",err)
    return close_redis(red)
end

local function get(key)
    local res,err = red:get(key)
    if not res then
        print("failed to get dog:",err)
        return close_redis(red)
    end

    if res == ngx.null then
        res = ''
    end
    return res
end
close_redis(red)